namespace Northwind.Domain.Core
{
    using System;
    using System.Threading;

    public static class CurrentPrincipalHelper
    {
        private static Func<string> GetCurrentPrincipal = () => Thread.CurrentPrincipal.Identity.Name;

        public static string Name
        {
            get {

                var identity = GetCurrentPrincipal();
                return string.IsNullOrWhiteSpace(identity) 
                    ? "Unknown"
                    : identity;
            }
        }

        public static void SetNameFunction(Func<string> func)
        {
            GetCurrentPrincipal = func;
        }
    }
}
